import java.util.Scanner;

public class test9 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(); // 货位总数
        int m = in.nextInt(); // 商品类别
        int[] numbers = new int[n]; //货架上编号
        int[] counts = new int[m+1]; // 出现次数 --> 从1开始

        for (int i = 0; i < n; i++) {
            numbers[i] = in.nextInt();
        }
        for (int i = 1; i <= m; i++) {
            counts[i] = in.nextInt();
        }
        int result = getResult(numbers,counts);
        System.out.println(result);
    }

    public static int getResult(int[] numbers,int[] counts){
        int result = Integer.MAX_VALUE;
        if(numbers.length==0||counts.length==0) return 0;

        int[] goodCount = new int[counts.length]; // 新数组
        // 使用滑动窗口
        int flag = 0; // 用来记录当前满足条件的种类数量
        int left=0,right = 0;
        while (right < numbers.length){
            int goods = numbers[right];
            right++; //选取当前
            if(goods>=1 && goods<= counts.length-1){
                // 表示这个位置放的是需要的物品
                goodCount[goods]++;
                // 还有一种情况,就是这个物品要的数量为0
                if(goodCount[goods]==counts[goods]) flag++; //表示有一种达标
                if(counts[goods]==0&&goodCount[goods]==1) flag++;
            }
            // 缩小范围
            while (flag==counts.length-1){
                result = Math.min(result,right-left); //最新长度
                int leftGood = numbers[left];
                left++;
                if(leftGood>=1 && leftGood<= counts.length-1) {
                    if(counts[leftGood] == goodCount[leftGood]) flag--;
                    goodCount[leftGood]--;
                }
            }
        }
        return result==Integer.MAX_VALUE?0:result;
    }
}
